--[[
	Temporary  Control Panel
	Just used for the test version
--]]
do
	local CreateFrame = IGAS.GUI.CreateFrame
	
	local panel = CreateFrame("Frame", "IGAS_STUDIO_ControlPanel", IGAS.Studio.UIParent)

	panel.Width =200
	panel.Height = 200
	panel.FrameStrata = "DIALOG"
	panel.Toplevel = true
	panel.Movable = true
	panel.MouseEnabled = true
	panel:SetBackdrop{
		bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
		edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
		tile = true, tileSize = 16, edgeSize = 16,
		insets = { left = 3, right = 3, top = 3, bottom = 3 }
	}
	panel:SetBackdropColor(0,0,0,1)
	panel:SetPoint("TOPRIGHT", IGAS.Studio.UIParent, "TOPRIGHT")
		
	-- Code Frame
	local codePanel = CreateFrame("Form", "CodeForm", panel)
	codePanel.Height = 400
	codePanel.Width = 500
	codePanel.Visible = false
	codePanel.Caption = ""
	codePanel:SetPoint("CENTER", IGAS.Studio.UIParent, "CENTER")
		
    local code = CreateFrame("MultiLineTextBox", "Code", codePanel)
    code:SetPoint("TOPLEFT", codePanel, "TOPLEFT", 4, -10)
    code:SetPoint("BOTTOMRIGHT", codePanel, "BOTTOMRIGHT", -4, 45)
	
	local btnCommit = CreateFrame("Button", "Ok", codePanel)
	btnCommit.Height = 24
	btnCommit.Width = 100
	btnCommit.Text = "Commit"
	btnCommit:SetPoint("BOTTOMRIGHT", codePanel, "BOTTOMRIGHT", -4, 20)
	
	-- Buttons
	local btnClear = CreateFrame("Button", "Clear", panel)
	btnClear.Height = 24
	btnClear.Width = 180
	btnClear.Style = "NORMAL"
	btnClear.Text = "Clear"
	btnClear:SetPoint("TOP", panel, "TOP", 0, -40)	
	
	local btnExport = CreateFrame("Button", "Export", panel)
	btnExport.Height = 24
	btnExport.Width = 180
	btnExport.Style = "NORMAL"
	btnExport.Text = "Export"
	btnExport:SetPoint("TOP", btnClear, "BOTTOM", 0, -20)
	
	local btnImport = CreateFrame("Button", "Import", panel)
	btnImport.Height = 24
	btnImport.Width = 180
	btnImport.Style = "NORMAL"
	btnImport.Text = "Import"
	btnImport:SetPoint("TOP", btnExport, "BOTTOM", 0, -20)
	
	local btnExit = CreateFrame("Button", "Exit", panel)
	btnExit.Height = 24
	btnExit.Width = 180
	btnExit.Style = "NORMAL"
	btnExit.Text = "Exit"
	btnExit:SetPoint("TOP", btnImport, "BOTTOM", 0, -20)
	
	-- Scripts	
	function panel:OnMouseDown()
		self:StartMoving()
	end

	function panel:OnMouseUp()
		self:StopMovingOrSizing()
	end	
	
	function btnClear:OnClick()
		IGAS.Studio.UIParent:Clear()
	end
	
	function btnExport:OnClick()
		codePanel.__Mode = "EXPORT"
		btnCommit.Text = "Okay"
		codePanel.Code.Text = S_UIParent:Export() or ""
		codePanel.Visible = true
	end
	
	function btnImport:OnClick()
		codePanel.__Mode = "IMPORT"
		btnCommit.Text = "Commit"
		codePanel.Visible = true
	end
	
	function btnExit:OnClick()
		UIParent:Show()
		IGAS.Studio.UIParent.Visible = false
	end
	
	function btnCommit:OnClick()
		if codePanel.__Mode == "IMPORT" then
			S_UIParent:Import(codePanel.Code.Text or "")
		end
		
		codePanel.Visible = false
	end
end